<?php
/*
 * Created on 2009-9-21
 * Author:liujun
 * Company:kingsoft Co.LTD
 * E-mail:chmod@live.cn
 

 */
 class Mail_model extends CI_Model{
	function __construct(){
		parent::__construct();
		//加载类库
		$this->load->library('email');
	}
	
	function sendMail($mail, $mailType = 'text'){
		if (	empty($mail['mailTo']) ||
				empty($mail['mailFrom']) ||
				empty($mail['displayName']) ||
				empty($mail['mailSubject']) || empty($mail['mailMessage'])){
			return false;
		}

		//初始化
//		$config['protocol'] = 'smtp'; //如果采用的是邮件代理服务器，请选择smtp，默认是用mail命令发送。
		$config['smtp_host'] = '216.18.195.35';
//		$config['smtp_port'] = '11211';
		$config['protocol'] = 'sendmail';
		$config['mailpath'] = '/usr/sbin/sendmail';
		$config['charset'] = 'utf-8';
		$config['wordwrap'] = TRUE;
		$config['smtp_timeout'] = 60;
		$config['wrapchars'] = 50;
		$config['mailtype'] = $mailType;
		$this->email->initialize($config);

		$mailTo = $mail['mailTo'];
		$mailFrom = $mail['mailFrom'];
		$displayName = $mail['displayName'];
		$mailSubject = $mail['mailSubject'];
		$mailMessage = $mail['mailMessage'];

		if(!empty($mail['mailReplay']) && !empty($mail['replayName'])){
			$mailReplay = $mail['mailReplay'];
			$replayName = $mail['replayName'];
			$this->email->reply_to($mailReplay, $replayName);
		}

		if(!empty($mail['mailBcc'])){
			$mailBcc = $mail['mailBcc'];
			$this->email->bcc($mailBcc);
		}
		$this->email->subject($mailSubject);
		$this->email->message($mailMessage);
		$this->email->from($mailFrom, $displayName);
		$this->email->to($mailTo);

		$mailLog = $this->email->print_debugger();
		$data = array( 	
						'mailTo' => $mailTo,
						'mailFrom' => $mailFrom,
						'mailName' => $displayName,
						'mailSubject' => $mailSubject,
						'mailDatetime' => date('Y-m-d', now()),
						'mailMessage' => $mailMessage,
						'mailLog' => $mailLog);
//		$this->security_model->logs($data, 'mailLog');
		return $this->email->send();
	}
 }
?>
